package com.ffcs.cn.action.desktopcontrol.smlinklabel;

import com.supermap.desktop.controls.ui.controls.SmDialog;
import com.supermap.desktop.controls.ui.controls.labels.SmLinkLabel;
import com.supermap.desktop.core.Application;
import com.supermap.desktop.core.ui.controls.GridBagConstraintsHelper;

import java.awt.*;


public class DialogSmLinkLabel extends SmDialog {
	private SmLinkLabel smLinkLabel;

	public DialogSmLinkLabel() {
		setTitle("带有链接的文本标签");
		setSize(new Dimension(300, 100));
		initComponents();
		initLayout();
	}

	private void initComponents() {
		smLinkLabel = new SmLinkLabel("点击次数");
		smLinkLabel.setActionCommand("odd");
		smLinkLabel.addActionListener(e -> {
			if (e.getActionCommand().equals("odd")) {
				Application.getActiveApplication().getOutput().output("奇数次点击");
				smLinkLabel.setActionCommand("dual");
			} else if (e.getActionCommand().equals("dual")) {
				Application.getActiveApplication().getOutput().output("偶数次点击");
				smLinkLabel.setActionCommand("odd");
			}
		});
	}

	private void initLayout() {
		this.setLayout(new GridBagLayout());
		this.add(smLinkLabel, new GridBagConstraintsHelper(0, 0, 1, 1)
				.setInsets(GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setWeight(1, 1)
				.setFill(GridBagConstraints.BOTH));
	}
}
